package net.service.impl;


import net.mapper.UserMapper;
import net.pojo.User;
import net.pojo.UserExample;
import net.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    UserMapper userMapper;

    //登录功能
    @Override
    public User findByNameAndPass(String username,String password) {
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        //查询username
        criteria.andUsernameEqualTo(username);
        //查询password
        criteria.andPasswordEqualTo(password);
        return userMapper.selectByExampleone(userExample);
    }

    //注册功能
    @Override
    public int register(User user) {
        return userMapper.insert(user);
    }

    //验证username
    @Override
    public int checkUserName(String username) {
        UserExample userExample = new UserExample();
        UserExample.Criteria criteria = userExample.createCriteria();
        //查询username
        criteria.andUsernameEqualTo(username);
        return userMapper.countByExample(userExample);
    }
}
